<?php
// functions for back-end uses

function wv_columns($cols) {
	unset($cols['date']);
	unset($cols['author']);
	$cols['coupon_code'] = __('Coupon Code');
	$cols['date'] = __('Date');
    return $cols;
}
add_filter('manage_edit-coupon_columns', 'wv_columns');


function wv_custom_column($column_name, $id) {
	global $post, $wvcr;
	
	if ($column_name == 'coupon_code') {
		$meta = $wvcr->coupon_mb->the_meta($id);
		$wvcr->coupon_mb->the_value('couponcode');
	}
	
}
add_action('manage_posts_custom_column', 'wv_custom_column', 10, 2);


add_filter('post_row_actions', 'wv_post_row_actions');
function wv_post_row_actions($actions)
{
	global $current_screen, $post;
	
	unset($actions['inline hide-if-no-js']);
	unset($actions['view']);
	
	if ($current_screen->id == 'edit-coupon') {
		$actions['add-options'] = sprintf('<a href="%1$s" title="%2$s">%2$s</a>', get_option_link($post->ID), __('Add Options'));
	}
	return $actions;
}

function get_option_link($postID = '')
{
	if ( ! $postID ) {
		return admin_url('edit.php?post_type=coupon&page=coupon-options');
	} else {
		return admin_url('edit.php?post_type=coupon&page=coupon-options&post='.$postID);
	}
}

function dropdown_coupons()
{
	$coupons = get_posts('post_type=coupon');
	print('<select name="post">');
	foreach ($coupons as $coupon) {
		printf('<option value="%s">%s</option>', $coupon->ID, $coupon->post_title);
	}
	print('</select>');
}

function printState($key, $value)
{
	if ($key == $value) {
		echo "selected";
	}
}

add_filter('post_updated_messages', 'wv_coupon_updated_messages');
function wv_coupon_updated_messages($messages)
{
	$messages['post'] = array(
		 0 => '', // Unused. Messages start at index 1.
		 1 => __('Coupon saved.'), 
		 2 => __('Custom field updated.'),
		 3 => __('Custom field deleted.'),
		 4 => __('Coupon saved.'),
		 6 => __('Coupon saved.'),
		 7 => __('Coupon saved.'),
		10 => __('Coupon draft updated.'),
	);
	return $messages;
}

function remove_publish_metabox() {
	remove_meta_box('submitdiv' , 'coupon' , 'normal'); 
}
add_action('admin_menu' , 'remove_publish_metabox');


?>